package cn.ycc1.boot3mq.controller;

import cn.ycc1.boot3mq.order.enums.OrderRabbit;
import lombok.RequiredArgsConstructor;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @author ycc
 * @date 2024/8/2
 */
@RestController
@RequiredArgsConstructor
public class TestController {
    private final RabbitTemplate rabbitTemplate;

    @GetMapping("/test")
    public String test() {
//        rabbitTemplate.convertAndSend(OrderRabbit.ORDER_CLOSE.exchange(), OrderRabbit.ORDER_CLOSE.routingKey(), orderInfo);
        rabbitTemplate.convertAndSend(OrderRabbit.ORDER_CLOSE.exchange(), OrderRabbit.ORDER_AUTO_PAID_TIMEOUT_CLOSE.routingKey(), "test-123");
        return "test";
    }

    @GetMapping("/test2")
    public String test2() {
        Map<String, Object> msg = new HashMap<>();
        msg.put("name", "张三");
        msg.put("age", 12);
        rabbitTemplate.convertAndSend(OrderRabbit.OBJECT_SEND.exchange(), OrderRabbit.OBJECT_SEND.routingKey(), msg);
        return "test object send";
    }
}
